package logic

import (
	"Junior_two/subject/usercenter/userrpc/internal/dao"
	"context"
	"net/http"

	"Junior_two/subject/usercenter/userrpc/internal/svc"
	"Junior_two/subject/usercenter/userrpc/pb/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type LogLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogLogic {
	return &LogLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LogLogic) Log(in *user.LogRequest) (*user.LogResponse, error) {
	// todo: add your logic here and delete this line
	if !dao.LogFliUsername(in.Username) {
		return &user.LogResponse{
			Msg:  "用户名不存在，请先注册",
			Code: http.StatusAccepted,
		}, nil
	}
	if !dao.LogFliPaw(in.Username, in.Password) {
		return &user.LogResponse{
			Msg:  "密码错误",
			Code: http.StatusAccepted,
		}, nil
	}
	return &user.LogResponse{
		Msg:  "登录成功",
		Code: http.StatusOK,
	}, nil
}
